<template>
  <div class="info-dialog">
    <el-dialog
      :visible.sync="visible"
      :title="title"
      :modal-append-to-body="true"
      :append-to-body="true"
      :destroy-on-close="false"
      :close-on-click-modal="false"
      :modal="true"
      top="10vh"
      @closed="closed"
    >

    <el-form :inline="true" :model="queryForm" class="demo-form-inline">
        <el-form-item label="">
          <el-input v-model="queryForm.keywords" placeholder="请输入关键字" style="width: 18.75rem;" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search"  size="mini" :loading="loading" @click="onQuerySubmit">查询</el-button>
          <el-button type="info" icon="el-icon-refresh"  size="mini" :loading="loading" @click="onReset">重置</el-button>
          <el-button type="warning" icon="el-icon-plus"  size="mini" :loading="loading" @click="handleAdd">添加</el-button>
        </el-form-item>
      </el-form>

    <el-table
      :data="tableData"
      border
      empty-text="暂无数据."
      border
      style="width: 100%">
      <el-table-column
        prop="name"
        label="区域名"
        width="180">
      </el-table-column>

      <el-table-column prop="coordType" label="坐标类型" >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.coordType='0' " type="success">经纬度</el-tag>
          <el-tag v-else type="danger">cad</el-tag>
        </template>
      </el-table-column>

      <el-table-column
        prop="coordZ"
        label="高度"
        width="100">
      </el-table-column>

      <el-table-column prop="coordZType" label="高度类型"  >
        <template slot-scope="scope">
          <el-tag v-if="scope.row.coordZType=='0' " >相对3D世界表面</el-tag>
          <el-tag v-if="scope.row.coordZType=='1' " >相对3D世界地面</el-tag>
          <el-tag v-if="scope.row.coordZType=='2' " >相对3D世界海拔</el-tag>
        </template>
      </el-table-column>

      <el-table-column label="操作" align="left" >
       <template slot-scope="scope">
         <el-button type="text" icon="el-icon-edit-outline" size="small" @click="handleEdit(scope.row)">编辑
         </el-button>
         <el-button type="text" icon="el-icon-delete" size="small" @click="handleDelete(scope.row)">删除
         </el-button>
       </template>
     </el-table-column>

    </el-table>

    <el-row>
      <el-col :span="24">
        <div align="right" style="margin-top: 0.3125rem;">
          <el-pagination background layout="prev, pager, next" :current-page="page.cur" :page-size="page.limit" :total="page.total" @current-change="handleCurrentChange" />
        </div>
      </el-col>
    </el-row>
    </el-dialog>

    <!--编辑框-->
    <RangeInfoDialog
      v-if="poiFormVisible"
      :dialog-visible="poiFormVisible"
      :dialog-data="poiFormData"
      @closed="poiFormClose"
      @refresh="load"
    />

  </div>
</template>

<script>
import {
  findSceneRangeList,
  deleteSceneRange
} from '@/api/51world/sceneSrcRange.js'

import {
  isOk
} from '@/utils/request'


import RangeInfoDialog from './children/RangeInfoDialog.vue'




export default {
  name: 'RangeStyleDialog',
  components: {
    RangeInfoDialog
  },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false
    },
    dialogData: {
      type: Object,
      default: () => ({})
    },
  },
  data() {
    return {
      visible: false,
      title: '',
      loading:false,
      queryForm:{
        keywords:'',
      },
      page: {
        cur: 1,
        limit: 10,
        total: 0
      },
      tableData: [],
      srcData:{},
      poiFormVisible:false,
      poiFormData : true
    }
  },
  computed: {
  },
  watch: {
    dialogVisible: {
      handler: function(value) {
        this.visible = value
      },
      immediate: true,
      deep: false
    },
    dialogData: {
      handler: function(nValue) {
        if (nValue) {
          this.srcData = nValue || {}
          this.title=nValue.name
        }
      },
      immediate: true,
      deep: false
    },
  },
  mounted: function() {
  },
  created() {
    this.load();
  },
  methods: {
    indexMethod(index) {
      return index +1;
    },
    onQuerySubmit(event) {
      this.load()
    },
    onReset(event) {
      this.queryForm.keywords='';
      this.load()
    },
    load(){
      this.loading=true
      findSceneRangeList({
        cur: this.page.cur,
        limit: this.page.limit,
        keywords: this.queryForm.keywords,
        srcId:this.srcData.id
      }).then(rsp => {
        if(200==rsp.code){
          const _data = rsp.data.list
          this.page.total = rsp.data.totalRow
          this.tableData = _data
          this.loading = false
        }
      }).catch(err => {
        console.log(err);
      })
      .finally(() => {
        this.loading = false
      })
    },
    handleCurrentChange(cur) {
      this.page.cur = cur
      this.load()
    },
    handleAdd: function(data) {
      this.poiFormVisible = true
      this.poiFormData = {
        srcId:this.srcData.id
      }
    },
    handleEdit: function(data) {
      this.poiFormVisible = true
      this.poiFormData = data
    },
    handleDelete: function(data) {
      this.$confirm('确认删除【' + data.label + '】吗？', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true
        deleteSceneRange({
          id: data.id
        }).then(response => {
          this.$message({
            message: '删除成功',
            type: 'success',
            duration: 500
          })
          this.load()
        }).catch(err => {
          console.log(err);
        })
        .finally(() => {
          this.loading = false
        })
      })
    },
    poiFormClose(e){
      this.poiFormVisible = e
      this.poiFormData = {}
      this.load()
    },
    closed: function() {
      this.$emit('closed', false)
    }
  }
}
</script>

<style lang="scss">
  .info-dialog {

  }
</style>
